import java.util.List;

//实现Iterator接口即可将BookShelfIterator视为Iterator进行处理
//具体迭代器角色类
public class BookIteratorImpl implements BookIterator
{
    private List<Book> list;
    //    private BookShelf bookShelf;
    private int index;

    public BookIteratorImpl(List<Book> list)
    {
        this.list = list;
    }

    //    public BookShelfIterator(BookShelf bookShelf) {
//        this.bookShelf = bookShelf;
//        this.index = 0;
//    }
    public boolean hasNext()
    {
        if (index < list.size())
        //if (index < bookShelf.getLength())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    //next方法返回目前该书（Book的对象实例），然后把index推到下一个为位置
    public Object next()
    {
        Book book = list.get(index);
//        Book book = bookShelf.getBookAt(index);
        index++;
        return book;
    }
}
